import 'package:flutter/material.dart';
import 'package:x3_base_package/x3_base_package.dart';

class BusinessCustomerItemAvatar extends StatelessWidget {
  final dynamic data;

  const BusinessCustomerItemAvatar({Key key, @required this.data})
      : assert(data != null),
        super(key: key);

  @override
  Widget build(BuildContext context) {
    return _buildVipImageWidget(context, this.data);
  }

  Widget _buildVipImageWidget(BuildContext context, dynamic data) {
    String vipBirthdayMonth = BaseUtils.getKeyData(data, 'vipBirthdayMonth').toString();
    String vipBirthdayDay = BaseUtils.getKeyData(data, 'vipBirthdayDay').toString();
    String vipAvatarUrl = BaseUtils.getKeyData(data, 'vipAvatarUrl').toString();
    String vipName = BaseUtils.getKeyData(data, 'vipName').toString();
    int initVipBirthdayMonth = int.tryParse(vipBirthdayMonth) ?? 0;
    int initVipBirthdayDay = int.tryParse(vipBirthdayDay) ?? 0;
    String birthday = BaseTransformUtil.format(initVipBirthdayMonth).toString() + '-' + BaseTransformUtil.format(initVipBirthdayDay).toString();
    TextStyle birthdayTextStyle = Theme.of(context).textTheme.bodyText2.copyWith(fontSize: 10.0);
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        BaseImageComponent(key: UniqueKey(), imageUrl: vipAvatarUrl, placeholderName: vipName, width: 56.0, height: 56.0, type: BaseImageTypeEnum.X3User, circular: 56.0, hero: UniqueKey().toString(), fit: BoxFit.cover),
        SizedBox(height: 1),
        Container(
          alignment: Alignment.center,
          padding: EdgeInsets.symmetric(vertical: 2, horizontal: 6.0),
          decoration: BoxDecoration(
            border: Border.all(color: Theme.of(context).scaffoldBackgroundColor, width: 0.8),
            borderRadius: BorderRadius.all(Radius.circular(12)),
          ),
          child: Container(
            alignment: Alignment.center,
            padding: EdgeInsets.only(bottom: 1.6),
            child: BaseComponentUtils.buildTextSpanWidget(['生日:', birthday], styles: {0: birthdayTextStyle, 1: birthdayTextStyle}),
          ),
        ),
      ],
    );
  }
}
